package cc.rengu.igas.momp.common.dao.impl;

import cc.rengu.igas.momp.common.dao.McMchntInfoMapper;
import cc.rengu.igas.momp.common.entity.*;
import cc.rengu.jradp.mods.dbs.Database;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.bean.PageResult;
import cc.rengu.oltp.utility.util.*;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Jinan Liu
 * @date 2020/3/26 00:21
 * @description 营销活动机构规则数据库操作接口实现
 */
public class McMchntInfoMapperImpl implements McMchntInfoMapper {

    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppParamConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);

    /**
     * @param instId
     * @param mcNo
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/3/26 00:24
     * @description 营销活动商户信息列表查询接口实现
     */
    @Override
    public List<TMMcMchntInfo> selectMcMchntInfoList(String instId, String mcNo) throws Exception {

        String queryClause = "INST_ID=[" + instId + "], MC_NO=[" + mcNo + "]";

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMcMchntInfoList");

        // 按接口赋查询条件
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        mcMchntInfo.setInstId(instId);
        mcMchntInfo.setMcNo(mcNo);

        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, mcMchntInfo, TMMcMchntInfo.class);
        if (null == objectList || objectList.isEmpty()) {
            rglog.error("根据查询条件<{}>获取营销活动商户信息列表失败!", queryClause);
            return null;
        }

        return objectList.stream().map(item -> (TMMcMchntInfo) (item)).collect(Collectors.toList());
    }

    /**
     * 营销活动商户规则列表查询数据库操作接口定义
     *
     * @param instId 法人机构号
     * @param mcNo   营销活动编号
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2021/8/10 20:18
     */
    public TMMcMchntInfo selectMcMchntInfoListCount(String instId, String mcNo) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMcMchntInfoListCount");

        // 按接口赋查询条件
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        mcMchntInfo.setInstId(instId);
        mcMchntInfo.setMcNo(mcNo);

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, mcMchntInfo, mcMchntInfo);
        if (Database.DBS_SUCCESS != iReturnCode) {
            rglog.error("法人机构号<{}>活动号<{}>商户数据量查询异常<{}>!", instId, mcNo, iReturnCode);
            return null;
        }
        return mcMchntInfo;

    }

    public TMMcMchntInfo selectMcMchntInfoListCount(String instId, String mcNo, String mchntType) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMcMchntInfoListCount");

        // 按接口赋查询条件
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        mcMchntInfo.setInstId(instId);
        mcMchntInfo.setMcNo(mcNo);
        mcMchntInfo.setMchntType(mchntType);
        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, mcMchntInfo, mcMchntInfo);
        if (Database.DBS_SUCCESS != iReturnCode) {
            rglog.error("法人机构号<{}>活动号<{}>商户范围类型<{}>商户数据量查询异常<{}>!", instId, mcNo, mchntType, iReturnCode);
            return null;
        }

        return mcMchntInfo;

    }

    /**
     * 营销活动商户规则列表新增数据库操作接口实现
     *
     * @param mcMchntInfoList 营销活动商户信息表
     * @return int 返回码
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/4/1 21:57
     */
    @Override
    public int insertMcMchntInfoListByBank(List<TMMcMchntInfo> mcMchntInfoList) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "insertMcMchntInfoListByBank");

        for (TMMcMchntInfo tmMcMchntInfo : mcMchntInfoList) {

            int iReturnCode = dbsUtil.dbsExecuteTransactionSql(sqlStr, tmMcMchntInfo, TMMcMchntInfo.class);
            if (Database.DBS_SUCCESS != iReturnCode) {
                rglog.error("插入法人机构号<{}>营销活动编号<{}>商户号<{}>的营销活动商户信息失败!<{}>", tmMcMchntInfo.getInstId(), tmMcMchntInfo.getMcNo(), tmMcMchntInfo.getMchntNo(), iReturnCode);
                return iReturnCode;
            }
        }

        return Database.DBS_SUCCESS;
    }

    /**
     * 营销活动商户规则列表更新数据库操作接口实现
     *
     * @param mcMchntInfoList
     * @return int 返回码
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/4/1 21:57
     */
    @Override
    public int updateMcMchntInfoListByBank(List<TMMcMchntInfo> mcMchntInfoList) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "updateMcMchntInfoListByBank");

        for (TMMcMchntInfo tmMcMchntInfo : mcMchntInfoList) {

            int iReturnCode = dbsUtil.dbsExecuteTransactionSql(sqlStr, tmMcMchntInfo, TMMcMchntInfo.class);
            if (Database.DBS_SUCCESS != iReturnCode) {
                rglog.error("更新法人机构号<{}>营销活动编号<{}>商户号<{}>的营销活动商户信息失败!<{}>", tmMcMchntInfo.getInstId(), tmMcMchntInfo.getMcNo(), tmMcMchntInfo.getMchntNo(), iReturnCode);
                return iReturnCode;
            }
        }

        return Database.DBS_SUCCESS;
    }

    /**
     * 营销活动商户规则列表删除数据库操作接口实现
     *
     * @param instId 法人机构号
     * @param mcNo   营销活动编号
     * @return int 返回码
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/4/1 21:57
     */
    @Override
    public int deleteMcMchntInfoListByBank(String instId, String mcNo) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "deleteMcMchntInfoListByBank");

        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(instId);
        tmMcMchntInfo.setMcNo(mcNo);

        int iReturnCode = dbsUtil.dbsExecuteTransactionSql(sqlStr, tmMcMchntInfo, TMMcMchntInfo.class);
        if (Database.DBS_SUCCESS != iReturnCode && Database.DBS_NOT_FOUND != iReturnCode) {
            rglog.error("删除法人机构号<{}>营销活动编号<{}>的营销活动商户信息失败!<{}>", tmMcMchntInfo.getInstId(), tmMcMchntInfo.getMcNo(), iReturnCode);
            return iReturnCode;
        }

        return Database.DBS_SUCCESS;
    }

    /**
     * 营销活动商户列表删除数据库操作接口实现
     *
     * @param instId 法人机构号
     * @param mcNo   营销活动编号
     * @return int 返回码
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/4/1 23:51
     */
    @Override
    public int deleteMcMchntInfoList(String instId, String mcNo, List<TMMcMchntInfo> mcMchntInfoList) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "deleteMcMchntInfo");

        for (TMMcMchntInfo tmMcMchntInfo : mcMchntInfoList) {

            int iReturnCode = dbsUtil.dbsExecuteTransactionSql(sqlStr, tmMcMchntInfo, TMMcMchntInfo.class);
            if (Database.DBS_SUCCESS != iReturnCode) {
                rglog.error("删除法人机构号<{}>营销活动编号<{}>商户号<{}>的营销活动商户信息失败!<{}>", tmMcMchntInfo.getInstId(), tmMcMchntInfo.getMcNo(), tmMcMchntInfo.getMchntNo(), iReturnCode);
                return iReturnCode;
            }
        }

        return Database.DBS_SUCCESS;
    }

    /**
     * 新增单条营销活动商户规则数据库操作接口实现
     *
     * @param instId      法人机构号
     * @param mcMchntInfo
     * @return int
     * @throws Exception
     * @author Jinan Liu
     * @date 2020/4/1 23:51
     */
    @Override
    public int insertMchntInfo(String instId, TMMcMchntInfo mcMchntInfo) throws Exception {
        return 0;
    }

    /**
     * 更新单条营销活动商户规则数据库操作接口实现
     *
     * @param instId      法人机构号
     * @param mcMchntInfo
     * @return int
     * @throws Exception
     * @author Jinan Liu
     * @date 2020/4/1 23:51
     */
    @Override
    public int updateMchntInfo(String instId, TMMcMchntInfo mcMchntInfo) throws Exception {
        return 0;
    }

    /**
     * 删除单条营销活动商户规则数据库操作接口实现
     *
     * @param instId  法人机构号
     * @param mcNo    营销活动编号
     * @param mchntNo
     * @return int
     * @throws Exception
     * @author Jinan Liu
     * @date 2020/4/1 23:51
     */
    @Override
    public int deleteMchntInfo(String instId, String mcNo, String mchntNo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "deletebyinstIdMcnoMchntNo");

        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(instId);
        tmMcMchntInfo.setMcNo(mcNo);
        tmMcMchntInfo.setMchntNo(mchntNo);
        int iReturnCode = dbsUtil.dbsExecuteTransactionSql(sqlStr, tmMcMchntInfo, TMMcMchntInfo.class);
        if (Database.DBS_SUCCESS != iReturnCode && Database.DBS_NOT_FOUND != iReturnCode) {
            rglog.error("删除法人机构号<{}>营销活动编号<{}>的营销活动商户信息失败!<{}>", tmMcMchntInfo.getInstId(), tmMcMchntInfo.getMcNo(), iReturnCode);
            return iReturnCode;
        }

        return Database.DBS_SUCCESS;
    }

    @Override
    public int deleteMchntInfoByType(String instId, String mcNo, String mchntType) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "deleteMcMchntInfoListByType");

        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(instId);
        tmMcMchntInfo.setMcNo(mcNo);
        tmMcMchntInfo.setMchntType(mchntType);
        int iReturnCode = dbsUtil.dbsExecuteTransactionSql(sqlStr, tmMcMchntInfo, TMMcMchntInfo.class);
        if (Database.DBS_SUCCESS != iReturnCode && Database.DBS_NOT_FOUND != iReturnCode) {
            rglog.error("删除法人机构号<{}>营销活动编号<{}>的营销活动商户信息失败!<{}>", tmMcMchntInfo.getInstId(), tmMcMchntInfo.getMcNo(), iReturnCode);
            return iReturnCode;
        }

        return Database.DBS_SUCCESS;
    }

    /**
     * 查询单条营销活动商户规则数据库操作接口实现
     *
     * @param instId  法人机构号
     * @param mcNo    营销活动编号
     * @param mchntNo
     * @return int
     * @throws Exception
     * @author Jinan Liu
     * @date 2020/4/1 23:51
     */
    @Override
    public int selectMchntInfoByPrimaryKey(String instId, String mcNo, String mchntNo) throws Exception {
        return 0;
    }

    /**
     * 使用商户基本信息检查商户是否参与收银员返现营销活动数据库操作接口实现
     *
     * @param tmMcMchntInfo
     * @return int
     * @throws Exception
     * @author Jinan Liu
     * @date 2020/4/8 10:14
     */
    @Override
    public TMMcMchntInfo checkIfMchntAttendCashierChashbackMc(TMMcMchntInfo tmMcMchntInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "checkIfMchntAttendCashierChashbackMc");

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, tmMcMchntInfo, tmMcMchntInfo);
        if (null == tmMcMchntInfo) {
            rglog.error("根据查询条件<{}>获取营销活动商户信息列表失败!", tmMcMchntInfo);
            return null;
        }

        return tmMcMchntInfo;
    }

    /**
     * 使用商户号和商圈号检查商户是否参与减免类营销活动或卡券类营销活动数据库操作接口实现
     *
     * @param mchntBaseInfo 商户基本信息表T_B_MCHNT_BASE_INFO
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/4/12 19:17
     */
    @Override
    public List<TMMcMchntInfo> matchMoMcInfoByMchntNoAndMchntArea(TBMchntBaseInfo mchntBaseInfo) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);

        /* 若商户信息中有商圈信息,使用商户号和商圈号一起查询,否则仅使用商户号查询 */
        String sqlStr;
        if (null == mchntBaseInfo.getMchntArea()) {
            /* 所属商圈为空,使用商户号判断 */
            sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "matchMcInfoByMchntNo");
        } else {
            /* 所属商圈非空,使用商户号和商圈号一起判断 */
            sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "matchMcInfoByMchntNoAndMchntArea");
        }

        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, mchntBaseInfo, TMMcMchntInfo.class);
        if (null == objectList || objectList.isEmpty()) {
            rglog.error("获取法人机构号<{}>的商户<{}>的营销活动商户信息列表失败!", mchntBaseInfo.getInstId(), mchntBaseInfo.getMchntNo());
            return null;
        }

        return objectList.stream().map(item -> (TMMcMchntInfo) (item)).collect(Collectors.toList());
    }

    /**
     * 使用商户号和商圈号检查商户是否参与卡券类营销活动数据库操作接口实现
     *
     * @param mcMchntOrderData 营销活动商户订单明细实体类
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/4/21 10:30
     */
    @Override
    public TMMcMchntInfo matchCpMcInfoByMchntNoAndMchntArea(McMchntOrderData mcMchntOrderData) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr;
        if (StringUtil.isEmptyOrNull(mcMchntOrderData.getMchntArea())) {
            /* 所属商圈为空,使用商户号判断 */
            sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "matchCpMcInfoByMchntNo");
        } else {
            /* 所属商圈非空,使用商户号和商圈号一起判断 */
            sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "matchCpMcInfoByMchntNoAndMchntArea");
        }

        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, mcMchntOrderData, tmMcMchntInfo);
        if (Database.DBS_SUCCESS != iReturnCode) {
            rglog.error("法人机构号<{}>商户号<{}>未参加卡券营销活动<{}>!", mcMchntOrderData.getInstId(), mcMchntOrderData.getMchntNo(), mcMchntOrderData.getMcNo(), iReturnCode);
            return null;
        }

        return tmMcMchntInfo;
    }

    /**
     * 使用主键查询营销活动商户信息
     *
     * @param instId
     * @param mcNo
     * @param mchntNo
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/5/30
     */
    @Override
    public TMMcMchntInfo selectTMMcMchntInfoByPrimaryKey(String instId, String mcNo, String mchntNo) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "mompSelectTMMcMchntInfoByPrimaryKey");

        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(instId);
        tmMcMchntInfo.setMcNo(mcNo);
        tmMcMchntInfo.setMchntNo(mchntNo);
        tmMcMchntInfo.setMchntType("0");

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, tmMcMchntInfo, tmMcMchntInfo);
        if (Database.DBS_SUCCESS != iReturnCode) {
            rglog.error("根据查询条件获取营销活动商户信息表失败!<{}>", iReturnCode);
            return null;
        }
        return tmMcMchntInfo;
    }

    /**
     * 更新营销活动商户信息表T_M_MC_MCHNT_INFO中的退出标志exit_flag
     *
     * @param tmMcMchntInfo
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/5/9
     */
    @Override
    public int updateTMMcMchntInfo(TMMcMchntInfo tmMcMchntInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "mompUpdateTMMcMchntInfo");
        tmMcMchntInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, tmMcMchntInfo, null);
        if (0 != iReturnCode) {
            rglog.error("根据主键更新营销活动商户信息表T_M_MC_MCHNT_INFO失败！");
        }
        return iReturnCode;
    }

    /**
     * 更新营销活动商户信息表T_M_MC_MCHNT_INFO中的退出标志exit_flag和 新商户标志newMchntFlag
     *
     * @param tmMcMchntInfo
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/7/9
     */
    @Override
    public int updateExitFlagAndNewMchntFlag(TMMcMchntInfo tmMcMchntInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "mompUpdateExitFlagAndNewMchntFlag");
        tmMcMchntInfo.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, tmMcMchntInfo, null);
        if (0 != iReturnCode) {
            rglog.error("根据主键更新营销活动商户信息表T_M_MC_MCHNT_INFO失败！");
        }
        return iReturnCode;
    }

    /**
     * 商户手续费优惠活动查询营销活动商户信息数据库操作接口实现
     *
     * @param mcMchntOrderData 营销活动商户订单明细实体类
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/7/8 10:16
     */
    @Override
    public TMMcMchntInfo matchMfdMcInfoByMchntNoAndMchntArea(McMchntOrderData mcMchntOrderData) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr;

        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();

        if (StringUtil.isEmptyOrNull(mcMchntOrderData.getMchntArea())) {
            /* 所属商圈为空,使用商户号判断 */
            sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "matchMfdMcInfoByMchntNo");
        } else {
            /* 所属商圈非空,使用商户号和商圈号一起判断 */
            sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "matchMfdMcInfoByMchntNoAndMchntArea");
        }

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, mcMchntOrderData, tmMcMchntInfo);
        if (Database.DBS_SUCCESS != iReturnCode) {
            rglog.error("法人机构号<{}>商户号<{}>未参加商户手续费优惠营销活动<{}>或已退出优惠!", mcMchntOrderData.getInstId(), mcMchntOrderData.getMchntNo(), mcMchntOrderData.getMcNo(), iReturnCode);
            return null;
        }

        return tmMcMchntInfo;
    }

    /**
     * @param instId
     * @param mchntNo
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author JL PANG
     * @date 2020/7/10
     * @description 营销活动商户信息列表查询接口实现
     */
    @Override
    public List<TMMcMchntInfo> selectMcMchntInfoListByinstIdMchntNo(String instId, String mchntNo, String mchntName) throws Exception {

        String queryClause = "INST_ID=[" + instId + "], MCHNT_NO=[" + mchntNo + "]";

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMcMchntInfoListByinstIdMchntNo");

        // 按接口赋查询条件
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        mcMchntInfo.setInstId(instId);
        mcMchntInfo.setMchntNo(mchntNo);
        mcMchntInfo.setMchntName(mchntName);
        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, mcMchntInfo, TMMcMchntInfo.class);
        if (null == objectList || objectList.isEmpty()) {
            rglog.error("根据查询条件<{}>获取营销活动商户信息列表失败!", queryClause);
            return null;
        }

        return objectList.stream().map(item -> (TMMcMchntInfo) (item)).collect(Collectors.toList());
    }

    /**
     * @param instId
     * @param mcNo
     * @param exitFlag     退出标志
     * @param newMchntFlag 新商户标志
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author JL Pang
     * @date 2020/3/26 00:24
     * @description 营销活动商户信息列表查询接口实现
     */
    @Override
    public List<TMMcMchntInfo> selectMcMchntInfoListByinstIdMcMoFlag(String instId, String mcNo, String exitFlag, String newMchntFlag) throws Exception {

        String queryClause = "INST_ID=[" + instId + "], MC_NO=[" + mcNo + "]";

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMcMchntInfoListByinstIdMcMoFlag");

        // 按接口赋查询条件
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        mcMchntInfo.setInstId(instId);
        mcMchntInfo.setMcNo(mcNo);
        mcMchntInfo.setExitFlag(exitFlag);
        mcMchntInfo.setNewMchntFlag(newMchntFlag);
        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, mcMchntInfo, TMMcMchntInfo.class);
        if (null == objectList || objectList.isEmpty()) {
            rglog.error("根据查询条件<{}>获取营销活动商户信息列表失败!", queryClause);
            return null;
        }

        return objectList.stream().map(item -> (TMMcMchntInfo) (item)).collect(Collectors.toList());
    }

    /**
     * 营销活动商户列表分页查询数据库操作接口定义（针对进行中新增商户)
     *
     * @param instId       法人机构号
     * @param mcNo         营销活动编号
     * @param exitFlag     退出标志
     * @param newMchntFlag 新商户标志
     * @return cc.rengu.oltp.utility.bean.PageResult 查询结果列表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2021/8/10 18:58
     */
    @Override
    public PageResult selectMcMchntInfoListByinstIdMcMoFlag(String instId, String mcNo, String exitFlag, String newMchntFlag, PageInfo pageInfo) throws Exception {

        String queryClause = "INST_ID=[" + instId + "], MC_NO=[" + mcNo + "]";

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMcMchntInfoListByinstIdMcMoFlag");

        // 按接口赋查询条件
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        mcMchntInfo.setInstId(instId);
        mcMchntInfo.setMcNo(mcNo);
        mcMchntInfo.setExitFlag(exitFlag);
        mcMchntInfo.setNewMchntFlag(newMchntFlag);

        return dbsUtil.dbsFetchPageListData(sqlStr, mcMchntInfo, TMMcMchntInfo.class, pageInfo);
    }

    /**
     * 商户参与银行对商户手续费减免活动列表
     *
     * @param mchntJoinMchntFeeDiscountInObj 商户参与银行对商户手续费减免活动列表查询 使用实体类入参
     * @param pageInfo                       数据库操作分页实体类
     * @return cc.rengu.oltp.utility.bean.PageResult 查询结果列表
     * @throws Exception 异常信息
     * @Author liujinan
     * @date 2020-09-11 19:44:41
     **/
    @Override
    public PageResult selectMchntJoinMchntFeeDiscount(MchntJoinMchntFeeDiscountInObj mchntJoinMchntFeeDiscountInObj, PageInfo pageInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMchntJoinMchntFeeDiscount");

        return dbsUtil.dbsFetchPageListData(sqlStr, mchntJoinMchntFeeDiscountInObj, MchntJoinMchntFeeDiscountOutObj.class, pageInfo);
    }

    @Override
    public int updateTMMcMchntInfoByStatus(TMMcMchntInfo tmMcMchntInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "updateTMMcMchntInfoByStatus");

        int iReturnCode = dbsUtil.dbsExecuteTransactionSql(sqlStr, tmMcMchntInfo, null);
        if (0 != iReturnCode) {
            rglog.error("根据主键更新营销活动商户信息表T_M_MC_MCHNT_INFO失败！");
        }
        return iReturnCode;
    }

    @Override
    public int insertTMMcMchntInfo(TMMcMchntInfo tmMcMchntInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "insertTMMcMchntInfo");

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, tmMcMchntInfo, tmMcMchntInfo);
        if (Database.DBS_SUCCESS != iReturnCode) {
            rglog.error("插入法人机构号<{}>营销活动编号<{}>营销活动商户号<{}>的营销活动商户信息表失败!<{}>", tmMcMchntInfo.getInstId(), tmMcMchntInfo.getMcNo(), tmMcMchntInfo.getMchntNo(), iReturnCode);
            return iReturnCode;
        }

        return Database.DBS_SUCCESS;
    }

    @Override
    public int updateTMMcMchntInfoByMcNo(TMMcMchntInfo tmMcMchntInfo) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "updateTMMcMchntInfoByMcNo");

        int iReturnCode = dbsUtil.dbsExecuteTransactionSql(sqlStr, tmMcMchntInfo, null);
        if (0 != iReturnCode) {
            rglog.error("根据主键更新营销活动商户信息表T_M_MC_MCHNT_INFO失败！");
        }
        return iReturnCode;
    }

    /**
     * @param instId
     * @param newMcNo
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author JL Pang
     * @date 2020/3/26 00:24
     * @description 根据 法人机构号 关联营销活动编号
     */
    @Override
    public List<TMMcMchntInfo> selectMchntByinstIdNewMcNo(String instId, String newMcNo) throws Exception {

        String queryClause = "INST_ID=[" + instId + "], NEW_MC_NO=[" + newMcNo + "]";

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMchntByinstIdNewMcNo");

        // 按接口赋查询条件
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        mcMchntInfo.setInstId(instId);
        mcMchntInfo.setNewMcNo(newMcNo);

        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, mcMchntInfo, TMMcMchntInfo.class);
        if (null == objectList || objectList.isEmpty()) {
            rglog.error("根据查询条件<{}>获取营销活动商户信息列表失败!", queryClause);
            return null;
        }

        return objectList.stream().map(item -> (TMMcMchntInfo) (item)).collect(Collectors.toList());
    }

    @Override
    public MchntJoinMchntFeeDiscountOutObj selectMchntJoinMchntFeeDiscountByMchntInfo(MchntJoinMchntFeeDiscountInObj mchntJoinMchntFeeDiscountInObj) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMchntJoinMchntFeeDiscountByMchntInfo");

        MchntJoinMchntFeeDiscountOutObj mchntJoinMchntFeeDiscountOutObj = new MchntJoinMchntFeeDiscountOutObj();

        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, mchntJoinMchntFeeDiscountInObj, mchntJoinMchntFeeDiscountOutObj);
        if (Database.DBS_SUCCESS != iReturnCode && iReturnCode != Database.DBS_NOT_FOUND) {
            rglog.error("根据查询条件获取营销活动信息失败!<{}>", iReturnCode);
            return null;
        }

        return mchntJoinMchntFeeDiscountOutObj;
    }

    /**
     * @param instId
     * @param mchntNo
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author JL PANG
     * @date 2020/11/04
     * @description 营销活动商户信息列表查询接口实现
     */
    @Override
    public List<TMMcMchntInfo> selectMfdMchntInfoListByinstIdMchntNo(String instId, String mchntNo) throws Exception {

        String queryClause = "INST_ID=[" + instId + "], MCHNT_NO=[" + mchntNo + "]";

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMfdMchntInfoListByinstIdMchntNo");

        // 按接口赋查询条件
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        mcMchntInfo.setInstId(instId);
        mcMchntInfo.setMchntNo(mchntNo);
        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, mcMchntInfo, TMMcMchntInfo.class);
        if (null == objectList || objectList.isEmpty()) {
            rglog.error("根据查询条件<{}>获取营销活动商户信息列表失败!", queryClause);
            return null;
        }

        return objectList.stream().map(item -> (TMMcMchntInfo) (item)).collect(Collectors.toList());
    }

    /**
     * 银行操作员查询所有卡券类营销活动信息数据库操作接口实现
     * 分页模式
     *
     * @param tmMcMchntInfo 营销活动商户列表查询使用实体类入参
     * @param pageInfo      数据库操作分页实体类
     * @return cc.rengu.oltp.utility.bean.PageResult 查询结果列表
     * @throws Exception 异常信息
     * @author JL Pang
     * @date 2020/12/21 15:04
     */
    @Override
    public PageResult selectMcMchntInfoList(TMMcMchntInfo tmMcMchntInfo, PageInfo pageInfo) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMcMchntInfoList");

        return dbsUtil.dbsFetchPageListData(sqlStr, tmMcMchntInfo, TMMcMchntInfo.class, pageInfo);
    }

    /**
     * 银行操作员查询营销活动所有商户信息数据库操作接口实现
     *
     * @param tmMcMchntInfo 营销活动商户列表查询使用实体类入参
     * @return cc.rengu.oltp.utility.bean.PageResult 查询结果列表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/12/21 15:04
     */
    @Override
    public List<Object> selectMcMchntInfoList(TMMcMchntInfo tmMcMchntInfo) throws Exception {

        String queryClause = "INST_ID=[" + tmMcMchntInfo.getInstId() + "], MC_NO=[" + tmMcMchntInfo.getMcNo() + "]";

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMcMchntInfoList");
        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, tmMcMchntInfo, TMMcMchntInfo.class);
        if (null == objectList || objectList.isEmpty()) {
            rglog.error("根据查询条件<{}>获取营销活动商户信息列表失败!", queryClause);
            return null;
        }

        return objectList.stream().map(item -> (TMMcMchntInfo) (item)).collect(Collectors.toList());

    }

    /**
     * @param instId
     * @param mcNo
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2021/2/26 16:24
     * @description 营销活动商户信息列表查询接口实现
     */
    @Override
    public List<TMMcMchntInfo> selectMcMchntInfoListByMcNo(String instId, String mcNo, String mchntType) throws Exception {

        String queryClause = "INST_ID=[" + instId + "], MC_NO=[" + mcNo + "]";

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "mompSelectMcMchntInfoList");

        // 按接口赋查询条件
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        mcMchntInfo.setInstId(instId);
        mcMchntInfo.setMcNo(mcNo);
        mcMchntInfo.setMchntType(mchntType);

        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, mcMchntInfo, TMMcMchntInfo.class);
        if (null == objectList || objectList.isEmpty()) {
            rglog.error("根据查询条件<{}>获取营销活动商户信息列表失败!", queryClause);
            return null;
        }

        return objectList.stream().map(item -> (TMMcMchntInfo) (item)).collect(Collectors.toList());
    }

    /**
     * 使用商户号和商圈号 活动号检查商户是否参与减免类营销活动或卡券类营销活动数据库操作接口实现
     *
     * @param mchntBaseInfo 商户基本信息表T_B_MCHNT_BASE_INFO
     * @param mcNo          活动号
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2021/6/18 19:17
     */
    @Override
    public List<TMMcMchntInfo> matchMoMcInfoByMchntNoAndMchntAreaAndMcNo(TBMchntBaseInfo mchntBaseInfo, String mcNo) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        rglog.error("DBPoolName=[{}]", dbPoolName);

        DbsUtil dbsUtil = new DbsUtil(dbPoolName);

        /* 若商户信息中有商圈信息,使用商户号和商圈号一起查询,否则仅使用商户号查询 */
        String sqlStr;
        if (null == mchntBaseInfo.getMchntArea()) {
            /* 所属商圈为空,使用商户号判断 */
            sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "matchMcInfoByMchntNoAndMcNo");
        } else {
            /* 所属商圈非空,使用商户号和商圈号一起判断 */
            sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "matchMcInfoByMchntNoAndMchntAreaAndMcNo");
        }
        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(mchntBaseInfo.getInstId());
        tmMcMchntInfo.setMcNo(mcNo);
        tmMcMchntInfo.setMchntNo(mchntBaseInfo.getMchntNo());
        tmMcMchntInfo.setRemark1(mchntBaseInfo.getMchntArea());
        List<Object> objectList = dbsUtil.dbsFetchLimitListData(sqlStr, tmMcMchntInfo, TMMcMchntInfo.class);
        if (null == objectList || objectList.isEmpty()) {
            rglog.error("获取法人机构号<{}>的商户<{}>的营销活动商户信息列表失败!", mchntBaseInfo.getInstId(), mchntBaseInfo.getMchntNo());
            return null;
        }

        return objectList.stream().map(item -> (TMMcMchntInfo) (item)).collect(Collectors.toList());
    }
}
